def nachalo(s):
    if s <= 1:
        return False
    if s <= 3:
        return True
    if s % 2 == 0 or s % 3 == 0:
        return False
    b = 5
    while b * b <= s:
        if s % b == 0 or s % (b + 2) == 0:
            return False
        b += 6
    return False

def nachalo_proverka(s):
    m = s
    while True:
        m += 1
        if nachalo(m):
            return m

def nachalo_proverka(s):
    m = s
    while m > 2:
        m -= 1
        if nachalo(m):
            return m

def konec(s):
    if not s.isdigit() or len(s) != 3:
        return "Wrong input"
    num = int(s)
    if nachalo(num):
        return num
    next_m = nachalo_proverka(num)
    prev_m = nachalo_proverka_m(num)
    if next_m - num < num - prev_m:
        return next_m
    else:
        return prev_m
slovar = {
    'zero': '0', 'one': '1', 'two': '2', 'three': '3', 'four': '4', 'five': '5',
    'six': '6', 'seven': '7', 'eight': '8', 'nine': '9'
}




slova = input().split()
if len(slova) != 3:
    print("Wrong input")
else:
    num_str = ''
    try:
        for word in slova:
            num_str += slovar[word.lower()]
        print(konec(num_str))
    except KeyError:
        print("Wrong input")
